www.gusucode.com > VC++ 客户管理系统(SQL Serve)-源码程序 > VC++ 客户管理系统(SQL Serve)-源码程序/code/Program/quyu.cpp
// quyu.cpp : implementation file // #include "stdafx.h" #include "khmanager.h" #include "quyu.h" #include "ado.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif int clnum=0; int quyuxiugai=0; ///////////////////////////////////////////////////////////////////////////// // quyu dialog quyu::quyu(CWnd* pParent /*=NULL*/) : CDialog(quyu::IDD, pParent) { //{{AFX_DATA_INIT(quyu) //}}AFX_DATA_INIT } void quyu::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(quyu) DDX_Control(pDX, IDC_EDIT6, m_edit6); DDX_Control(pDX, IDC_LIST1, m_list); DDX_Control(pDX, IDC_EDIT5, m_edit5); DDX_Control(pDX, IDC_EDIT4, m_edit4); DDX_Control(pDX, IDC_EDIT3, m_edit3); DDX_Control(pDX, IDC_EDIT2, m_edit2); DDX_Control(pDX, IDC_EDIT1, m_edit1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(quyu, CDialog) //{{AFX_MSG_MAP(quyu) ON_COMMAND(ID_ADD, OnAdd) ON_COMMAND(ID_DELETE, OnDelete) ON_COMMAND(ID_EXIT, OnExit) ON_COMMAND(ID_SAVE, OnSave) ON_COMMAND(ID_UPDATE, OnUpdate) ON_COMMAND(ID_CANCEL, OnCancel) ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // quyu message handlers BOOL quyu::OnInitDialog() { CDialog::OnInitDialog(); // toolbarteg tool; // tool.toolbarstart(this->GetSafeHwnd()); imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0); imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON1))); imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON2))); imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON3))); imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON4))); imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON5))); imagelist.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON10))); CString s; TCHAR *pString; menu.LoadMenu(IDR_lxrxx); toolbar.EnableAutomation(); toolbar.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,ID_TOOLBAR); toolbar.SetImageList(&imagelist); int i; for(i=0;i<8;i++) { button[i].dwData=0; button[i].fsState=TBSTATE_ENABLED; button[i].fsStyle=TBSTYLE_BUTTON; } button[5].fsStyle=TBSTYLE_SEP; button[0].idCommand=ID_ADD; button[0].iBitmap=0; button[1].idCommand=ID_UPDATE; button[1].iBitmap=1; button[2].idCommand=ID_DELETE; button[2].iBitmap=2; button[3].idCommand=ID_SAVE; button[3].iBitmap=3; button[4].idCommand=ID_CANCEL; button[4].iBitmap=4; button[6].idCommand=ID_EXIT; button[6].iBitmap=5; for(i=0;i<8;i++) { s.LoadString(i+IDS_21); int nStringLength= s.GetLength() + 1; pString = s.GetBufferSetLength(nStringLength); button[i].iString =toolbar.AddStrings(pString); s.ReleaseBuffer(); } toolbar.AddButtons(7,button); toolbar.AutoSize(); toolbar.SetStyle(TBSTYLE_FLAT|CCS_TOP); toolbar.EnableButton(ID_SAVE,false); toolbar.EnableButton(ID_CANCEL,false); m_list.ModifyStyle(0L,LVS_REPORT); // m_list.ModifyStyle(0L,LVS_SINGLESEL); m_list.ModifyStyle(0L,LVS_SHOWSELALWAYS); m_list.ModifyStyle(0L,LVS_NOSORTHEADER); m_list.SetExtendedStyle(LVS_EX_GRIDLINES| LVS_EX_FULLROWSELECT| LVS_EX_HEADERDRAGDROP| LVS_EX_ONECLICKACTIVATE); m_list.InsertColumn(0,"区域编号"); m_list.InsertColumn(1,"区域名称"); m_list.InsertColumn(2,"区域级别"); m_list.InsertColumn(3,"区域重要程度"); m_list.InsertColumn(4,"区域购买力描述"); m_list.InsertColumn(5,"备注信息"); m_list.SetColumnWidth(0,100); m_list.SetColumnWidth(1,100); m_list.SetColumnWidth(2,100); m_list.SetColumnWidth(3,100); m_list.SetColumnWidth(4,100); m_list.SetColumnWidth(5,100); this->loadlist(); this->enbalewin(false); this->datatotext(); this->texttowin(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void quyu::autonum() { ado rst3; // _RecordsetPtr m_pRecordset; //m_pRecordset= order by qyxx_id asc rst3.rstOpen("select * from tb_Client_qyxx "); int k=rst3.GetRecordCount(); // long k=m_pRecordset->GetRecordCount(); if(k==0) { this->m_edit1.SetWindowText("QY001"); this->m_edit1.EnableWindow(false); return; } rst3.MoveLast(); CString mm=rst3.GetFieldValue("qyxx_id"); //m_pRecordset->MoveLast(); // CString mm=(char*)(_bstr_t)m_pRecordset->GetCollect((_bstr_t)"qyxx_id"); int xuhao=atoi(mm.Right(3)); xuhao+=1; mm.Format("QY%03d",xuhao); this->m_edit1.EnableWindow(false); this->m_edit1.SetWindowText(mm); rst3.close(); } void quyu::OnAdd() { this->enbalewin(true); this->enablebutton(false); this->clearall(); this->autonum(); } void quyu::OnCancel() { this->enbalewin(false); this->enablebutton(true); quyuxiugai=0; this->datatotext(); this->texttowin(); } void quyu::OnDelete() { ado rst; CString ss,aa; this->m_edit1.GetWindowText(aa); if(aa.IsEmpty()) {MessageBox("不能为空","提示"); return;} if(MessageBox("删除后数据将丢失","提示",MB_YESNO)==IDYES) { ss.Format("delete from tb_Client_qyxx where qyxx_id = '%s'",aa); rst.ExecuteSQL(ss); // this->sort(); //rst.close(); m_list.DeleteAllItems(); this->loadlist(); this->datatotext(); this->texttowin(); } } void quyu::OnExit() { this->EndDialog(true); } void quyu::OnSave() { ado rst; this->wintotext(); CString ss,srept; srept.Format("select * from tb_Client_qyxx where qyxx_qymc='%s'",edit5); rst.rstOpen(srept); if(rst.GetRecordCount()>0) { MessageBox("这个区域名称已经存在了","提示"); return; } if(quyuxiugai==1) {ss.Format("UPDATE tb_Client_qyxx set qyxx_qymc='%s',qyxx_qyjb='%s',qyxx_zscd='%s',qyxx_qygml='%s',qyxx_bz='%s'where qyxx_id='%s'",edit5,edit2,edit6,edit3,edit4,edit1);} else {ss.Format("INSERT INTO tb_Client_qyxx values('%s','%s','%s','%s','%s','%s')",edit1,edit5,edit2,edit6,edit3,edit4);} rst.ExecuteSQL(ss); m_list.DeleteAllItems(); this->loadlist(); this->datatotext(); this->texttowin(); this->enbalewin(false); this->enablebutton(true); //rst.close(); quyuxiugai=0; } void quyu::OnUpdate() { CString ss,aa; this->m_edit1.GetWindowText(aa); if(aa.IsEmpty()) {MessageBox("不能为空","提示"); return;} this->enbalewin(true); this->enablebutton(false); quyuxiugai=1; } void quyu::clearall() { this->m_edit1.SetWindowText(""); this->m_edit2.SetWindowText(""); this->m_edit3.SetWindowText(""); this->m_edit4.SetWindowText(""); this->m_edit5.SetWindowText(""); this->m_edit6.SetWindowText(""); } void quyu::enablebutton(bool butn) { toolbar.EnableButton(ID_ADD,butn); toolbar.EnableButton(ID_UPDATE,butn); toolbar.EnableButton(ID_DELETE,butn); toolbar.EnableButton(ID_SAVE,!butn); toolbar.EnableButton(ID_CANCEL,!butn); } void quyu::enbalewin(bool wi) { this->m_edit1.EnableWindow(wi); this->m_edit2.EnableWindow(wi); this->m_edit3.EnableWindow(wi); this->m_edit4.EnableWindow(wi); this->m_edit5.EnableWindow(wi); this->m_edit6.EnableWindow(wi); } void quyu::texttowin() { this->m_edit1.SetWindowText(edit1); this->m_edit2.SetWindowText(edit2); this->m_edit3.SetWindowText(edit3); this->m_edit4.SetWindowText(edit4); this->m_edit5.SetWindowText(edit5); this->m_edit6.SetWindowText(edit6); } void quyu::wintotext() { this->m_edit1.GetWindowText(edit1); this->m_edit2.GetWindowText(edit2); this->m_edit3.GetWindowText(edit3); this->m_edit4.GetWindowText(edit4); this->m_edit5.GetWindowText(edit5); this->m_edit6.GetWindowText(edit6); } void quyu::datatotext() { edit1=m_list.GetItemText(clnum,0); edit5=m_list.GetItemText(clnum,1); edit2=m_list.GetItemText(clnum,2); edit6=m_list.GetItemText(clnum,3); edit3=m_list.GetItemText(clnum,4); edit4=m_list.GetItemText(clnum,5); } void quyu::loadlist() { ado rst; rst.rstOpen("select * from tb_Client_qyxx"); int recordcount=rst.GetRecordCount(); int ii; for(ii=1;ii<=recordcount;ii++) { m_list.InsertItem(ii-1,""); m_list.SetItemText(ii-1,0,rst.GetFieldValue("qyxx_id")); m_list.SetItemText(ii-1,1,rst.GetFieldValue("qyxx_qymc")); m_list.SetItemText(ii-1,2,rst.GetFieldValue("qyxx_qyjb")); m_list.SetItemText(ii-1,3,rst.GetFieldValue("qyxx_zscd")); m_list.SetItemText(ii-1,4,rst.GetFieldValue("qyxx_qygml")); m_list.SetItemText(ii-1,5,rst.GetFieldValue("qyxx_bz")); rst.Move(ii); } rst.close(); } void quyu::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here clnum=m_list.GetHotItem(); if(clnum<0) {return;} this->datatotext(); this->texttowin(); this->enbalewin(false); this->enablebutton(true); *pResult = 0; } void quyu::sort() { ado rst3; rst3.rstOpen("select * from tb_Client_qyxx"); int k=rst3.GetRecordCount(); CString mm,sql; sql.Format("UPDATE tb_Client_qyxx set qyxx_id='%s'",mm); int i; for(i=1;i<=k;i++) { mm.Format("QY%03d",i); //MessageBox(mm,"提示"); rst3.ExecuteSQL(sql); rst3.Move(i); } } BOOL quyu::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message==WM_KEYDOWN && pMsg->wParam==13) pMsg->wParam=9; return CDialog::PreTranslateMessage(pMsg); }